namespace myWebApi.Repository;
using myWebApi.Domain;
using Microsoft.EntityFrameworkCore;
public class EFRepository<T> : IRepository<T> where T : class
{
    private readonly BookDbContext _db;
    private readonly DbSet<T> _tb;
    public EFRepository(BookDbContext db)
    {
        _db = db;
        _tb = db.set<T>()


}
    public async Task<T>? GetAllAsync()
    {
        return await _tb.ToListAsync();
    }
    public async Task<T> GetOneAsync(int id)
    {
        var obj = await _tb.FindAync(id);
        if (obj == null)
        {
            return null;

        }
        return obj;
    }
    public async Task<T> AddAsync(T entity)
    {
        var obj = await _tb.AddAsync(entity);
        await _db.SaveChangsAsync();
        return obj.Entity;
    }
    public async Task<T> DeleteAsync(T entity)
    {
        var obj = _tb.Remove(entity)
      await _db.SaveChangsAsync();
        return obj.Entity;


    }
}